#include <myheader_c_plus.h>
#include <unordered_map>
using std::endl;
using std::istringstream;
using std::cout;
using std::string;
using std::unordered_map;
using std::ifstream;
class WordTrans
{
public:
    void createmap(string & filename)
    {
        //打开文件输出流
        ifstream is(filename);
        string line;
        while(getline(is, line))
        {
            string key;
            string remain_word;
            istringstream iss(line);
            if(iss >> key)
            {
                remain_word = line.substr(line.find(' ') + 1);
                dic[key] = remain_word;
            }
        }
        for(auto & ele : dic)
        {
            cout << ele.first << " : " << ele.second << endl;
        }
    }

    void trans(string & filename)
    {
        string line;
        ifstream fs(filename);
        string word;
        while(getline(fs, line))
        {
            istringstream iss(line);
            while(iss >> word)
            {
                auto it = dic.find(word);
                if(it != dic.end())
                {
                    word = it->second;
                }
                cout << word << " ";
            }
        cout << endl;
         }
    }

private:
    unordered_map<string, string> dic;
};

int main(int argc, char *argv[])
{
    WordTrans wt;
    string filename = "map.txt";
    string filename2 = "trans.txt";

    wt.createmap(filename);
    wt.trans(filename2);
    return 0;
}

